package com.dk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dk.pojo.CarUser;
import com.dk.mapper.CarUserMapper;
import com.dk.service.CarUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 张成涛
 * @since 2021-08-11
 */
@Service
public class CarUserServiceImpl extends ServiceImpl<CarUserMapper, CarUser> implements CarUserService {
    @Resource
    private CarUserMapper tbUserMapper;

    @Override
    public CarUser findTbUserByName(String username) {
        QueryWrapper<CarUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);
        List<CarUser> tbUserList = tbUserMapper.selectList(queryWrapper);
        return tbUserList == null || tbUserList.size() <= 0 ? null : tbUserList.get(0);
    }

    @Override
    public CarUser getInfoByUserName(String username) {
        QueryWrapper<CarUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);
        List<CarUser> list = tbUserMapper.selectList(queryWrapper);
        if (list != null && list.size() >0) {
            CarUser user = (CarUser) list.get(0);
            return user;
        }
        return null;
    }

    @Override
    public void insetUser(CarUser carUser) {
        tbUserMapper.insert(carUser);
    }
}
